<?php

define('ACC', true);
require('./include/init.php');
session_start(); 
//print_r($_SESSION);
$userid = $_SESSION['user_id'];

echo '<head><meta charset = "utf-8"></head>';  
//$userid = 26;
 echo '<h2>分类账簿&nbsp|&nbsp<a href = "dashboard.php">返回虚拟公司主页</a></h2><br/>';    

$company = new companymodel();
$companyinfo = $company->getcompanyinfo($userid);
$companyid = $companyinfo['company_id'];
$accounting = new accountingmodel(); 
$companyy = $companyinfo['company_y'];  
$companyq = $companyinfo['company_q']; 

echo '<h2>公司名称为:' . $companyinfo['company_name'], '&nbsp|&nbsp';
echo '目前所在财年:第' . $companyinfo['company_y'] . '财年', '&nbsp|&nbsp';
echo '目前所在季度:第' . $companyinfo['company_q'] . '季度', '</h2><br/><br/>';

$currentasset = $accounting->getfinancialreport($companyid, $companyy, $companyq, 'balance sheet', 'current asset');
$noncurrentasset = $accounting->getfinancialreport($companyid, $companyy, $companyq, 'balance sheet', 'non current asset');
$currentliability =  $accounting->getfinancialreport($companyid, $companyy, $companyq, 'balance sheet', 'current liability');
$noncurrentliability =  $accounting->getfinancialreport($companyid, $companyy, $companyq, 'balance sheet', 'non current liability');
$equity =  $accounting->getfinancialreport($companyid, $companyy, $companyq, 'balance sheet', 'equity');
$totalasset = 0;
$totalliability = 0;
$totalequity = 0;
echo '<h3>资产负债表</h3>';

echo '<table border = "1">';
echo '<tr>';
echo '<td   width = "500">';
echo '<h4>流动资产</h4>';
$sum = 0;
foreach($currentasset as $k=>$v){
    echo '&nbsp&nbsp' . $k . '&nbsp&nbsp|&nbsp&nbsp' . $v . '<br/>';
    $sum = $sum + $v;
}
echo '<h4>流动资产合计: ' . $sum . '</h4><br/>';
$totalasset = $totalasset + $sum;

echo '<h4>非流动资产</h4>';
$sum = 0;
foreach($noncurrentasset as $k=>$v){
    echo '&nbsp&nbsp' . $k . '&nbsp&nbsp|&nbsp&nbsp' . $v . '<br/>';
    $sum = $sum + $v;
}
echo '<h4>非流动资产合计: ' . $sum . '</h4><br/>';
$totalasset = $totalasset + $sum; 

echo '<h3>总资产: ' . $totalasset . '</h3><br/>'; 

echo '</td>';
echo '<td   width = "500">';

echo '<h4>流动负债</h4>';
$sum = 0;
foreach($currentliability as $k=>$v){
    echo '&nbsp&nbsp' . $k . '&nbsp&nbsp|&nbsp&nbsp' . $v . '<br/>';
    $sum = $sum + $v;
}
echo '<h4>流动负债合计: ' . $sum . '</h4><br/>';
$totalliability = $totalliability  + $sum;

echo '<h4>非流动负债</h4>';
$sum = 0;
foreach($noncurrentliability as $k=>$v){
    echo '&nbsp&nbsp' . $k . '&nbsp&nbsp|&nbsp&nbsp' . $v . '<br/>';
    $sum = $sum + $v;
}
echo '<h4>非流动负债合计: ' . $sum . '</h4><br/>';
$totalliability = $totalliability  + $sum;
echo '<h3>总负债: ' . $totalliability . '</h3><br/>'; 


echo '<h4>所有者权益</h4>';
$sum = 0;
foreach($equity as $k=>$v){
    echo '&nbsp&nbsp' . $k . '&nbsp&nbsp|&nbsp&nbsp' . $v . '<br/>';
    $sum = $sum + $v;
}
echo '<h4>所有者权益合计: ' . $sum . '</h4><br/>';
$totalequity = $totalequity  + $sum;
echo '<h3>负债与所有者权益合计: ' . ($totalequity + $totalliability) . '</h3><br/>';  
echo '</td>'; 
echo '</tr>';
echo '</table>';
  


  
  
?>
